package com.awesumgames.awesum.sprites;

import com.awesumgames.awesum.AwesumGlobal.Awesum;
import com.awesumgames.awesum.Game;
import com.awesumgames.awesum.Quaternion;
import com.awesumgames.awesum.RunnableTree;
import com.awesumgames.awesum.Vector3;
import com.awesumgames.awesum.Models.Model;

public abstract class SpriteBase extends RunnableTree {
	public int texture = -1;
	protected int _file = -1;
	public Vector3 pos = new Vector3();
	public Vector3 moveTo = new Vector3();
	//public Object bitmap = null;
	
	//public TraitGl gl = null;
	public TraitMove move = null;
	//public TraitFram fram = null;
	//public TraitTran tran = null;
	//public TraitColl coll = null;
	//public TraitPhys phys = null;
	
	public Model	model = null;
	public Vector3	scale = new Vector3(1f, 1f, 1f),
					translate = new Vector3();
	public Quaternion quat = new Quaternion();
	
	public static class SpriteCoords {
		public float x1, x2, y1, y2;
		SpriteCoords(float x, float y, float width, float height) {
			x1 = x;
			x2 = x + width;
			y1 = y;
			y2 = y + height;
		}
	}
	public static SpriteCoords getCoords(int x, int y, int gridWidth, int gridHeight) { //TODO: probably move this into tileset
		float cellWidth = 1f / (float)gridWidth,
			  cellHeight = 1f / (float)gridHeight;
		float cx = x * cellWidth,
			  cy = y * cellHeight;
		return new SpriteCoords(cx, cy, cellWidth, cellHeight);
	}
	
	public SpriteBase() {
		Awesum.debug("Sprite constructor called without a resource image. Make sure to use the right constructor.");
	}
	public SpriteBase(int resFile) {
		_file = resFile;
	}
	
	public void load() {
		if (_file == -1) {
			Awesum.debug("Error loading sprite: resource image not set! Make sure to use the right constructor.");
			return;
		}
			
		texture = Game.Textures.load(_file);
		
		super.load();
	}

	private class Trait2d {
		public Sprite parent;
		Trait2d(Sprite dParent) {parent = dParent;}
	}
	
	public class TraitMove extends Trait2d {
		TraitMove(Sprite dParent) {
			super(dParent);
		}
		
	}
}
